﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class UserControl_Aging : System.Web.UI.UserControl
{
    Aging ag;
    AgingInfo agi;
    AgingItem agitem;
    IList<AgingInfo> agis;
    private string _agingID;

    public string agingID
    {
        get
        {
            return _agingID;
        }
        set
        {
            _agingID = value;
        }
    }

    public UserControl_Aging()
    {
        ag = new Aging();
        agitem = new AgingItem();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        BindAging();
        BindAgingItem();
    }

    protected void BindAging()
    {
        if (!string.IsNullOrEmpty(agingID))
        {
            agi = ag.GetbyAgingID(agingID);
            agis = new List<AgingInfo>();
            agis.Add(agi);
            this.DetailsView1.DataSource = agis;
            this.DetailsView1.DataBind();
            this.DetailsView1.Visible = true;
            this.DetailsView2.DataSource = agis;
            this.DetailsView2.DataBind();
            this.DetailsView2.Visible = true;
            this.DetailsView3.DataSource = agis;
            this.DetailsView3.DataBind();
            //Response.Write(this.DetailsView3.Rows[0].Cells[1].Text);
            this.DetailsView3.Visible = true;
            this.DetailsView4.DataSource = agis;
            this.DetailsView4.DataBind();
            this.DetailsView4.Visible = true;
            this.DetailsView7.DataSource = agis;
            this.DetailsView7.DataBind();
            this.DetailsView7.Visible = true;
            /*
             * 屏蔽质量恒温开始确认与巡查确认数据的绑定
            this.DetailsView6.DataSource = agis;
            this.DetailsView6.DataBind();
            this.DetailsView6.Visible = true;
            this.DetailsView8.DataSource = agis;
            this.DetailsView8.DataBind();
            this.DetailsView8.Visible = true;
             */
            this.DetailsView9.DataSource = agis;
            this.DetailsView9.DataBind();
            this.DetailsView9.Visible = true;
            this.DetailsView10.DataSource = agis;
            this.DetailsView10.DataBind();
            this.DetailsView10.Visible = true;
        }
    }

    protected void DetailsView2_DataBound(object sender, EventArgs e)
    {
        DetailsView d = (DetailsView)sender;
        if (DateTime.Parse(d.Rows[8].Cells[1].Text) == DateTime.Parse("2900/1/1 0:00:00"))
        {
            d.Rows[8].Cells[1].Text = "";
        }
    }

    protected void BindAgingItem()
    {
        //this.ListBox1.Items.Clear();
        //foreach (AgingItemInfo aii in agitem.GetAgingItemsbyID(agingID))
        //{
        //    this.ListBox1.Items.Add(aii.ProductSN);
        //}
        List<AgingItemInfo> list = (List<AgingItemInfo>)agitem.GetAgingItemsbyID(agingID);
        this.ListBox1.DataSource = list;
        this.ListBox1.DataTextField = "ProductSN";
        this.ListBox1.DataBind();
        this.Label1.Text = list.Count.ToString();
    }

    protected void DetailsView3_DataBound(object sender, EventArgs e)
    {
        checkformat2(sender);
    }
    protected void DetailsView4_DataBound(object sender, EventArgs e)
    {
        checkformat(sender);
    }

    protected void DetailsView7_DataBound(object sender, EventArgs e)
    {
        checkformat(sender);
    }
        
    //屏蔽质量恒温开始确认与巡查确认数据的绑定
    protected void DetailsView6_DataBound(object sender, EventArgs e)
    {
        //checkformat(sender);
    }

    protected void DetailsView8_DataBound(object sender, EventArgs e)
    {
        //checkformat(sender);
    }

    protected void DetailsView9_DataBound(object sender, EventArgs e)
    {
        checkformat(sender);
    }

    protected void DetailsView10_DataBound(object sender, EventArgs e)
    {
        checkformat2(sender);
    }

    protected static void checkformat(object sender)
    {
        DetailsView d = (DetailsView)sender;
        if (DateTime.Parse(d.Rows[0].Cells[1].Text) == DateTime.Parse("1900/1/1 0:00:00"))
        {
            d.Rows[0].Cells[1].Text = "";
        }
    }

    protected static void checkformat2(object sender)
    {
        DetailsView d = (DetailsView)sender;
        //Response.Write(d.Rows[0].Cells[1].Text == "1900-1-1 0:00:00");
        if (DateTime.Parse(d.Rows[0].Cells[1].Text) == DateTime.Parse("1900/1/1 0:00:00") && d.Rows[2].Cells[1].Text == "0")
        {
            d.Rows[0].Cells[1].Text = "";
            d.Rows[2].Cells[1].Text = "";
        }
    }
}
